'''
  This Source Code Form is subject to the terms of the Mozilla Public
  License, v. 2.0. If a copy of the MPL was not distributed with this
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
'''
def log(level: str, module: str, info: str, if_print):
    from conf import logger as conf
    import swe.time as stime
    if not level in conf.logLevels:
        raise TypeError("Invaild log level.")
    
    tmp: list = list()
    
    tmp.append(stime.formatedSysTime())
    tmp.append(level)
    tmp.append(module)
    tmp.append(info)
    
    loginfo = str(tmp)
    
    if conf.logLevels.index(level) >= conf.logLevels.index(conf.logLevel) and conf.recordLog:
        with open(conf.logFilePath, 'a', encoding = conf.logEncoding) as file:
            file.write("\n" + loginfo)
    if if_print or conf.forcePrint:
        print(loginfo)#异步的话一定要交回控制权
#    del tmp, module, level, info, if_print